package cn.virens.config;

import java.io.IOException;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.virens.util.ResourceUtil;

@Configuration
public class PropertiesConfig {

	/** 加载配置文件 */
	@Bean("propertiesBean")
	public PropertiesFactoryBean propertiesFactoryBean() throws IOException {
		PropertiesFactoryBean factoryBean = new PropertiesFactoryBean();
		factoryBean.setLocations(ResourceUtil.getResources("classpath:config/*.properties"));

		return factoryBean;
	}

	/** 注入配置文件 */
	@Bean("propertyPlaceholderConfigurer")
	public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer(@Qualifier("propertiesBean") Properties properties) throws IOException {
		PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
		configurer.setProperties(properties);

		return configurer;
	}
}
